package com.cmcc.zysoft.infocollection.dao;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.cmcc.zysoft.infocollection.model.News;
import com.cmcc.zysoft.infocollection.model.ReadNews;
import com.starit.common.dao.hibernate.HibernateBaseDaoImpl;
/**
 * 
 * @author zhou.dong
 * @2012-12-18
 */
@Repository
public class ReadNoticeDao extends HibernateBaseDaoImpl<ReadNews, String> {	
	@Resource
	private JdbcTemplate jdbcTemplate;

    public int count(String newsId,String userId){
		
		String countSql ="SELECT COUNT(*) FROM tb_b_read_news where news_type='0'and news_id="+newsId+" and user_id="+userId;
		return this.jdbcTemplate.queryForInt(countSql);
	}
    
    
    public void saveReadNews(String newsId,String userId) {
    	   ReadNews readNews = new ReadNews();
    	   readNews.setReadNewsId(String.valueOf(System.currentTimeMillis()));
    	   News news = new News();
    	   news.setNewsId(newsId);
//    	   news.setNewsType("0");
    	 //  readNews.setNews(news);
    	   readNews.setUserId(userId);
//    	   readNews.setNewsType("0");
    	   Date date = new Date();
    	   readNews.setReadDate(new java.sql.Date(date.getTime()));
    	   this.save(readNews);
	}
    
    /**
     *删除指定id的记录 
     * @param newsId
     */
    public void deleteReadNews(String newsId) {
          String sql="DELETE * FROM Tb_b_read_news where news_id="+newsId;
          this.jdbcTemplate.execute(sql);
    };
    
    /**
	 * 查出指定newsId 的ReadNews
	 */
    public  List<ReadNews> queryReadNewById(String newsId){
    	 List<ReadNews> list = this.findByNamedParam("news.newsId", newsId);
    	 
    	return list;
    }


}
